package com.ecp.commons.file;

import java.util.Date;
import java.util.Random;
import java.text.SimpleDateFormat;

public class TempFileName {

	private String	TempFileName	= "";

	public TempFileName() {
	}

	public TempFileName(String fileName) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		Date date = new Date();
		Random random = new Random();
		int randomNum = random.nextInt(1000);
		int index = fileName.lastIndexOf(".");
		String fileExt = "";
		if (index > 0) {
			fileExt = fileName.substring(index);
		}
		this.TempFileName = dateFormat.format(date) + randomNum + fileExt;
	}

	public String getTempFileName() {
		return this.TempFileName;
	}

	public static String getTempFileName(String fileName) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
		Date date = new Date();
		Random random = new Random();
		int randomNum = random.nextInt(1000);
		int index = fileName.lastIndexOf(".");
		String fileExt = "";
		if (index > 0) {
			fileExt = fileName.substring(index);
		}
		return dateFormat.format(date) + randomNum + fileExt;
	}
}
